/* 
 * File:   particle.h
 * Author: oddi
 *
 * Created on October 2, 2010, 4:11 PM
 */

#ifndef _PARTICLE_H
#define	_PARTICLE_H

#ifndef __GSL_RANDIST_H__
#include "gsl/gsl_randist.h"
#endif
#include "global_definitions.h"


#ifdef	__cplusplus
extern "C" {
#endif

    #define PARTICLE_ACTIVE 0
    #define PARTICLE_INACTIVE 1

    typedef struct struct_particle {
        pos3d pos;
        speed3d speed;
        floatdig trspeed;
        int active;
    } particle;

    typedef struct struct_particles {
        floatdig charge;
        floatdig mass;
        particle* particles;
        int num_of_particles;
        gsl_rng* r; //inner random number generator
    } particles_set;

    typedef particles_set* pset;

    void particle_initialize_particle_set(particles_set* set, int N, floatdig charge, floatdig mass);

    void particle_clear_particle_set(particles_set*);

    void particle_distribute_particle_set_speed_maxwell(particles_set*, double, int);

    /*distribute particles in space along the specified axe according to choosen distribution*/
    void particle_distrubute_particles_set_pos_uniform(particles_set* set, int axe, floatdig min_pos, floatdig max_pos);

    void particle_add_particle(particles_set*, particle*);

    void particle_remove_particle(particles_set*, int);

    particle* particle_get_particle(particles_set*, int);

    int particle_get_num_of_particles(particles_set*);

    void particle_make_pos_disturbance(particles_set* set, floatdig ap, floatdig k, int axe);
    void particle_distribute_particle_set_beam(particles_set* set, floatdig beam_speed, int axe);
    void particle_make_speed_disturbance(particles_set* set, floatdig as, floatdig k, int axe);

    void particle_set_two_beams(particles_set* set, floatdig v01, floatdig sigma1,
                            floatdig v02, floatdig sigma2, floatdig min_z, floatdig max_z);
    void particle_dump_particles_pos_into_file(particles_set* set, char* path, char* filename, floatdig pos, floatdig dz);
    void particle_dump_particles_speed_into_file(particles_set* set, char* path, char* filename, floatdig pos, floatdig dz);
    void particle_dump_trenergy_into_file(particles_set* set, char* path,
                                       char* filename, floatdig pos,
                                       floatdig dz, floatdig num_of_steps);
    void particle_set_particle_speed_maxwellian(particles_set* set, int particle, int axe, floatdig sigma);

    #ifdef DEBUG
    void particle_put_particles_pos_into_file(char*, particles_set*, int);
    void particle_put_particles_speed_into_file(char*, particles_set*, int);
    #endif


#ifdef	__cplusplus
}
#endif

#endif	/* _PARTICLE_H */

